{% extends base.html %}

{% block title %}{{ options.site_name }} - {{ tsk.taskname }} - 迅雷离线下载分享{% end %}
{% block desc %}{% if tsk.tags %}TAGS:{{ ", ".join(tsk.tags) }}{% end %} UP主:{{ email2name(tsk.creator) or tsk.creator or "unknow" }}{% end %}

{% block head %}
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script> !window.jQuery && document.write('<script type="text/javascript" src=\"{{static_url("js/jquery-1.4.3.min.js")}}\"><\/script>'); </script>
<script type="text/javascript" src="{{static_url('js/fancybox/jquery.fancybox-1.3.4.pack.js')}}"></script>
<script src="http://pstatic.xunlei.com/js/base64.js"></script>
<script type="text/javascript" src="{{static_url('js/common.js')}}"></script>
<script type="text/javascript">
  LE.taskname = {% raw json_encode(tsk.taskname) %};
  LE.links = function () {
    var result = [];
    var select = $("input.select");
    $.each($(".file-title > a"), function(i, n) {
      n = $(n);
      if (select[i].checked) result.push({url: n.attr("href"), title: n.text()});
    });
    return result;
  };
  LE.cookie = "{{ cookie }}".split(";")[0];
  LE.show = function(str) {
    $("#tip").text("返回");
    $("#link-text").val(str);
    $("ul.file-list").hide();
    $("#toggle").hide();
    $("#link-text").get(0).style.height="0";
    $("#link-text").show();
    $("#link-text").get(0).style.height=$("#link-text").get(0).scrollHeight+"px"
  };
  LE.hide = function() {
    $("#tip").text("批量下载");
    $("ul.file-list").show();
    $("#toggle").show();
    $("#link-text").hide();
  };
  LS.share_url = {% raw json_encode(request.protocol+"://"+request.host+"/share/"+str(task_ids)) %};
  LS.share_title = {% raw json_encode(tsk.taskname+u" - 迅雷离线下载分享 - "+options.site_name) %};
</script>
<link rel="stylesheet" href="{{static_url('js/fancybox/jquery.fancybox-1.3.4.css')}}" type="text/css" media="screen" />
<link rel="canonical" href="{{ request.protocol }}://{{ request.host }}/share/{{ task_ids }}" />
{% end %}

{% block body %}
<div class="lixian-box">
{% if not options.using_xss and not handler.disabled_userjs() and handler.get_cookie("xss") != gdriveid %}
  {% set iframe_src = "%s#cross-cookie|%s://%s/xss?gdriveid=%s" % (options.cross_cookie_url, request.protocol, request.host, gdriveid) %}
  <a href="{{ options.cross_userscript or static_url(options.cross_userscript) }}" target="_blank" class="cross-cookie" data-version="{{ options.cross_cookie_version }}">您尚未安装或需要升级 cross-cookie 点击前往UserScript.org安装</a>
  <script src="/xss_check.js?gdriveid={{ gdriveid }}"></script>
  <iframe src="{{ iframe_src }}" style="display: none;"></iframe>
{% end %}

<!--Share bar-->
<div class="task-info">
    <div id="share-button" class="task-button">
      <a href="/share/{{ task_ids }}" target="_blank"><div>分享</div></a>
      <div id="share-links" class="more-links" style="display: none;">
        <a href="javascript:LS.share_google();" title="分享到 Google+"><div class="task-button">Google+</div></a>
        <a href="javascript:LS.share_twitter();" title="分享到 Twitter+"><div class="task-button">Twitter</div></a>
        <a href="javascript:LS.share_sina();" title="分享到 新浪微博"><div class="task-button">新浪微博</div></a>
        <a href="javascript:LS.share_qq();" title="分享到 腾讯微博"><div class="task-button">腾讯微博</div></a>
        <a href="javascript:LS.share_douban();" title="分享到 豆瓣"><div class="task-button">豆瓣</div></a>
      </div>
    </div>
    <div id="batch-button" class="task-button">
      <a href="javascript:LE.hide();"><div id="tip">批量下载</div></a>
      <div id="batch-links" class="more-links" style="display:none;">
        <a href="javascript:LE.wget_links();"><div class="task-button">wget</div></a>
        <a href="javascript:LE.aria2_links();"><div class="task-button">aria2x10</div></a>
        <a href="javascript:LE.lixian_links();"><div class="task-button">迅雷导出</div></a>
        <a class="export" href="/export/{{ url_escape(options.site_name) }}_idm_{{ task_ids }}.ef2"><div class="task-button">IDM 导出</div></a>
        <a class="export" href="/export/{{ url_escape(options.site_name) }}_orbit_{{ task_ids }}.olt"><div class="task-button">Orbit导出</div></a>
        <a class="export" href="/export/{{ url_escape(options.site_name) }}_aria2c_{{ task_ids }}.down"><div class="task-button">aria2导出</div></a>
      </div>
    </div>
    <div class="clearfix"></div>
</div>
<!--Share bar end-->  

{% for task, files in tasks %}
  <div class="task-info">
      
      <div class="task-name">
        {% if task.status == "finished" %}
          <input type="checkbox" id="toggle" checked="true" />
          <label for="toggle"></label>
        {% end %}
          <span id="title">{{ task.taskname }}</span>
      </div>
    <!--{% if task.status == "finished" %}
    <div id="share-button" class="task-button">
      <a href="/share/{{ task.id }}" target="_blank"><div>分享</div></a>
      <div id="share-links" class="more-links" style="display: none;">
        <a href="javascript:LS.share_google();" title="分享到 Google+"><div class="task-button">Google+</div></a>
        <a href="javascript:LS.share_twitter();" title="分享到 Twitter+"><div class="task-button">Twitter</div></a>
        <a href="javascript:LS.share_sina();" title="分享到 新浪微博"><div class="task-button">新浪微博</div></a>
        <a href="javascript:LS.share_qq();" title="分享到 腾讯微博"><div class="task-button">腾讯微博</div></a>
        <a href="javascript:LS.share_douban();" title="分享到 豆瓣"><div class="task-button">豆瓣</div></a>
      </div>
    </div>
    <div id="batch-button" class="task-button">
      <a href="javascript:LE.hide();"><div id="tip">批量下载</div></a>
      <div id="batch-links" class="more-links" style="display: none;">
        <a href="javascript:LE.wget_links();"><div class="task-button">wget</div></a>
        <a href="javascript:LE.aria2_links();"><div class="task-button">aria2x10</div></a>
        <a href="javascript:LE.lixian_links();"><div class="task-button">迅雷导出</div></a>
        <a class="export" href="/export/{{ url_escape(options.site_name) }}_idm_{{ task.id }}.ef2"><div class="task-button">IDM 导出</div></a>
        <a class="export" href="/export/{{ url_escape(options.site_name) }}_aria2c_{{ task.id }}.down"><div class="task-button">aria2导出</div></a>
      </div>
    </div>
    {% else %}
    <div class="task-button">
      <a href="/share/{{ task.id }}" target="_blank">
        <div class="{{ task.status }}">{{ format_status(task.status) }}</div>
      </a>
    </div>
    {% end %}-->
    <div class="clearfix"></div>
  </div>
  <ul class="file-list">
    {% for i,file in enumerate(files) %}
    <li class="file-item">
      <div class="process-bar {{ file.status }}" style="width: {{ 100-file.process }}%"></div>
      <div class="file-title">
          {% if file.lixian_url %}
          <input  id="fi-{{task.id}}-{{i}}" type="checkbox" class="select"  checked="true" />
          <label for="fi-{{task.id}}-{{i}}" class="select" style="display:none;"></label>
          <a href="{{ file.lixian_url }}" target="_blank">{{ file.title }}</a>
          {% else %}
          <input  id="fi-{{task.id}}-{{i}}" type="checkbox" style="display: none" disabled />
          {{ file.title }}
          {% end %}
      </div>
      <div class="file-size">{{ format_size(file.size) }}</div>
      <div class="file-2lixian task-button" style="display:none;"><a>使用迅雷下载</a></div>
      <div class="clearfix"></div>
    </li>
    {% end %}
  </ul>
  <div>
    <textarea id="link-text" style="display: none;"></textarea>
  </div>
  
{% end %}
</div>
<div class="hidden">
  <a href="#disabled_cross_cookie" id="disable-helper"></a>
  <div id="disabled_cross_cookie">
    <dl>
      <dd>您已经禁用或尚未安装跨站Cookie脚本，无法使用浏览器直接下载。</dd>
      <dt>
        <ul>
          <li><a href="javascript:$.fancybox.close();">好吧，我使用批量下载功能下载</a></li>
          <li><a href="{{ options.cross_userscript }}" target="_blank">我要使用浏览器直接下载资源</a></li>
        </ul>
      </dt>
    </dl>
  </div>
</div>
{% end %}

{% block foot %}
<script type="text/javascript">
$(document).ready(function(){
  $("#batch-button").hover(function() {
    $("#batch-links").show();
  }, function() {
    $("#batch-links").hide();
  });

  $("#share-button").hover(function() {
    $("#share-links").show();
  }, function() {
    $("#share-links").hide();
  });

  $(".file-item").hover(function() {
    var _this = $(this);
    var t = _this.find(".file-title > a");
    if (t && t.attr("href")) {
      if (!_this.find(".file-2lixian a").attr("href"))
        _this.find(".file-2lixian a").attr("href", thunder_url_fix(t.attr("href"), t.text()));
      _this.find(".file-2lixian").show()
    }
  }, function() {
      $(this).find(".file-2lixian").hide()
  })

  if (localStorage) {
    var custom = '<a id="custom-button" title="右键点击编辑" href="javascript:LE.custom();"><div class="task-button">'+(LE.custom_script && LE.custom_script.name || '自定义')+'</div></a>';
    if (LE.custom_script) {
      $("#batch-links").prepend(custom);
    } else {
      $("#batch-links").append(custom);
    }
    $("#custom-button").bind("contextmenu", function() {
      LE.show(LE.custom_script && LE.custom_script.toString() || LE.default_script.toString());
      $("#tip").text("保存");
      $("#tip").click(function() {
        localStorage.custom_script = $("#link-text").val();
        if (localStorage.custom_script)
          eval("LE.custom_script = "+localStorage.custom_script);
        else
          LE.custom_script = undefined;
        $("#tip").unbind();
      });
      return false;
    });
  }

  var select = $(".file-list input.select");
  var selected = select.length;
  select.change(function() {
      if (this.checked) {
         selected++;
      } else {
         selected--;
      }
      if (selected==0) {
          $("#toggle").attr("checked", false);
      } else {
          $("#toggle").attr("checked", true);
      }
  });
  $("#toggle").click(function(){
      $(".file-list input:checkbox").show();
      $("#batch-links > a.export").mouseover(function(){
          var exports=[];
          $(".file-list input:checkbox").each(function(i,n){if (n.checked) exports.push(i)});
          $(this).attr("href", $(this).attr("href").replace(/(\?.*)?$/, "?i="+exports.join(",")))
      });
      var checked=this.checked;
      selected = checked ? select.length : 0;
      select.each(function(i,n){n.checked=checked});

      $("#toggle").unbind();
      $("#toggle").click(function(){
          var checked = this.checked;
          selected = checked ? select.length : 0;
          select.each(function(i,n){n.checked=checked});
      });
  });

  $("#disable-helper").fancybox();
  {% if handler.disabled_userjs() %}
  $(".file-title > a").click(function() {
      $("#disable-helper").click();
      return false;
  });
  {% end %}
});
{% if options.using_xss %}
document.write('<script type="text/javascript" src="/xssjs"><\/script>');
{% end %}
</script>
{% end %}
